package routers

import (
	"gin-shop-admin/controller"
	"gin-shop-admin/middleware"
	"github.com/gin-gonic/gin"
	"net/http"
)

func SetupRouters() (r *gin.Engine) {
	r = gin.Default()
	r.Static("/static", "static")
	r.LoadHTMLGlob("templates/*")
	r.GET("/", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index.html", nil)
	})

	r.Use(middleware.Cors(),)

	r.GET("/register", controller.RegisterHandler)
	r.POST("/login", controller.LoginHandler)

	r.GET("/product_list", controller.ProductList)
	r.GET("/product", controller.ProductGet)
	r.POST("/product", controller.ProductAdd)
	r.PUT("/product/:id", controller.ProductUpdate)
	r.DELETE("/product/:id", controller.ProductDelete)
	r.POST("/upload/image", controller.UploadImage)
	r.GET("/managers", controller.GetManagers)
	apiV1Group := r.Group("api/v1")
	apiV1Group.Use(middleware.JWTAuth(), middleware.CheckPermission())
	{
		apiV1Group.POST("/login", controller.BackendLogin)

		// 管理员相关API
		// 获取所有管理员列表
		apiV1Group.GET("/managers", controller.GetManagers)
		// 修改管理员状态信息
		apiV1Group.PUT("/manager/:uid/state/:state", controller.UpdateManagerState)
		// 添加一个管理员
		apiV1Group.POST("/manager", controller.AddOneManager)
		// 根据Uid获取管理员信息
		apiV1Group.GET("/manager/:uid", controller.GetManager)
		// 更新指定管理员信息
		apiV1Group.PUT("/manager", controller.UpdateManager)
		// 删除指定管理员
		apiV1Group.DELETE("/manager/:uid", controller.DeleteManager)
		// 修改管理员权限
		apiV1Group.PUT("/manager/:uid/role", controller.UpdateManagerRole)

		// 权限相关Api
		// 获取所有权限列表
		apiV1Group.GET("/permissions/list", controller.GetPermissionList)
		// 获取所有权限树形结构
		apiV1Group.GET("/permissions/tree", controller.GetPermissionTree)
		// 左侧菜单列表
		apiV1Group.GET("/menus", controller.GetMenus)

		// 角色相关API
		// 获取所有角色以及权限列表
		apiV1Group.GET("/roles", controller.GetRoles)
		// 删除指定角色的某个权限
		apiV1Group.DELETE("/roles/:roleID/permissions/:permissionID", controller.DeleteRolePermission)
		// 重新分配指定角色的权限列表
		apiV1Group.PUT("/roles/:roleID/permissions", controller.UpdateRolePermissions)
		// 根据ID查询角色信息
		//apiV1Group.GET("/roles/:id", controller.GetRoleByID)
		// 添加角色
		//apiV1Group.POST("/roles", controller.AddOneRole)
		// 修改指定角色信息
		//apiV1Group.PUT("/roles/:id", controller.UpdateRoleInfo)
		//apiV1Group.DELETE("/roles/:id", controller.DeleteOneRole)

		// 商品分类相关
		apiV1Group.GET("/categories", controller.GetGoodsCategory)
		apiV1Group.POST("/categories", controller.AddOneCategory)
		apiV1Group.PUT("/categories/:id", controller.UpdateOneCategory)
		apiV1Group.DELETE("/categories/:id", controller.DeleteOneCategory)

		apiV1Group.GET("/categories/:cat_id/attributes", controller.GetCategoryAttribute)
		apiV1Group.GET("/categories/:cat_id/attributes/:attr_id", controller.GetCategoryOneAttribute)
		apiV1Group.POST("/categories/:cat_id/attributes", controller.AddCategoryAttribute)
		apiV1Group.PUT("/category/:cat_id/attributes/:attr_id", controller.UpdateCategoryAttribute)
		apiV1Group.DELETE("/categorie/:cat_id/attributes/:attr_id", controller.DeleteOneAttribute)

		apiV1Group.GET("/goods", controller.GetGoodsList)
		apiV1Group.DELETE("/goods/:id", controller.DeleteOneGoods)
		apiV1Group.POST("/upload", controller.Upload)
		apiV1Group.POST("/goods", controller.AddOneGoods)
		apiV1Group.GET("/orders", controller.GetOrders)

		apiV1Group.GET("reports/type/1", controller.GetReportData)
	}
	return
}
